﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ShellViewModel.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the <seealso cref="ShellViewModel" /> type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Client.Desktop.ViewModel
{
    using System.Windows.Input;
    using Hisaab.Client.Common.BaseClasses;
    using Hisaab.Client.Common.Commands;
    using Hisaab.Client.Desktop.Commands;
    using Hisaab.Client.Desktop.Properties;
    using Stema.Controls;

    /// <summary>
    /// Defines the <seealso cref="ShellViewModel"/> type.
    /// </summary>
    public class ShellViewModel : ViewModelBase
    {
        /// <summary>
        /// Member variable _userName
        /// </summary>
        private string _userName;

        /// <summary>
        /// Member variable _exitApplication
        /// </summary>
        private ICommand _exitApplication;

        /// <summary>
        /// Member variable _selectedItem
        /// </summary>
        private NavigationPaneItem _selectedItem;

        /// <summary>
        /// Initializes a new instance of the <see cref="ShellViewModel"/> class.
        /// </summary>
        public ShellViewModel()
        {
            Title = string.Format("{0} - {1}", Resources.ApplicationName, Resources.Slogan);
        }

        /// <summary>
        /// Gets or sets the name of the user.
        /// </summary>
        /// <value>
        /// The name of the user.
        /// </value>
        public string UserName
        {
            get
            {
                return _userName;
            }

            set
            {
                _userName = value;
                RaisePropertyChangedEvent("UserName");
            }
        }

        /// <summary>
        /// Gets the exit application.
        /// </summary>
        /// <value>
        /// The exit application.
        /// </value>
        public ICommand ExitApplication
        {
            get
            {
                return _exitApplication ?? (_exitApplication = new ExitCommand());
            }
        }

        /// <summary>
        /// Gets or sets the selected item.
        /// </summary>
        /// <value>The selected item.</value>
        public NavigationPaneItem SelectedItem
        {
            get
            {
                return _selectedItem;
            }

            set
            {
                _selectedItem = value;
                RaisePropertyChangedEvent("SelectedItem");
                if (_selectedItem != null)
                {
                    var command = _selectedItem.GetValue(NavigationItemSelectCommand.SelectedCommandProperty) as ICommand;
                    if (command != null)
                    {
                        command.Execute(null);
                    }
                }
            }
        }
    }
}